#include <wx/slider.h>
#include "wxsslider.h"

namespace {
  wxsRegisterItem<wxsSlider> Reg( _T( "Slider" ), _T( "滑动框" ), wxsTWidget, _T( "标准" ), 110 );
  WXS_ST_BEGIN( wxsSliderStyles, _T( "" ) )
  WXS_ST( wxSL_HORIZONTAL )
  WXS_ST( wxSL_VERTICAL )
  WXS_ST( wxSL_AUTOTICKS )
  WXS_ST( wxSL_LABELS )
  WXS_ST( wxSL_LEFT )
  WXS_ST( wxSL_TOP )
  WXS_ST( wxSL_RIGHT )
  WXS_ST( wxSL_BOTTOM )
  WXS_ST( wxSL_BOTH )
  WXS_ST( wxSL_SELRANGE )
  WXS_ST( wxSL_INVERSE )
  WXS_ST_DEFAULTS()
  WXS_ST_END()
  WXS_EV_BEGIN( wxsSliderEvents )
  WXS_EVI( EVT_COMMAND_SCROLL, wxEVT_SCROLL_TOP | wxEVT_SCROLL_BOTTOM | wxEVT_SCROLL_LINEUP | wxEVT_SCROLL_LINEDOWN | wxEVT_SCROLL_PAGEUP | wxEVT_SCROLL_PAGEDOWN | wxEVT_SCROLL_THUMBTRACK | wxEVT_SCROLL_THUMBRELEASE | wxEVT_SCROLL_CHANGED, wxScrollEvent, CmdScroll )
  WXS_EVI( EVT_COMMAND_SCROLL_TOP, wxEVT_SCROLL_TOP, wxScrollEvent, ScrollTop )
  WXS_EVI( EVT_COMMAND_SCROLL_BOTTOM, wxEVT_SCROLL_BOTTOM, wxScrollEvent, CmdScrollBottom )
  WXS_EVI( EVT_COMMAND_SCROLL_LINEUP, wxEVT_SCROLL_LINEUP, wxScrollEvent, CmdScrollLineUp )
  WXS_EVI( EVT_COMMAND_SCROLL_LINEDOWN, wxEVT_SCROLL_LINEDOWN, wxScrollEvent, CmdScrollLineDown )
  WXS_EVI( EVT_COMMAND_SCROLL_PAGEUP, wxEVT_SCROLL_PAGEUP, wxScrollEvent, CmdScrollPageUp )
  WXS_EVI( EVT_COMMAND_SCROLL_PAGEDOWN, wxEVT_SCROLL_PAGEDOWN, wxScrollEvent, CmdScrollPageDown )
  WXS_EVI( EVT_COMMAND_SCROLL_THUMBTRACK, wxEVT_SCROLL_THUMBTRACK, wxScrollEvent, CmdScrollThumbTrack )
  WXS_EVI( EVT_COMMAND_SCROLL_THUMBRELEASE, wxEVT_SCROLL_THUMBRELEASE, wxScrollEvent, CmdScrollThumbRelease )
  WXS_EVI( EVT_COMMAND_SCROLL_CHANGED, wxEVT_SCROLL_CHANGED, wxScrollEvent, CmdScrollChanged )
  WXS_EVI( EVT_COMMAND_SLIDER_UPDATED, wxEVT_COMMAND_SLIDER_UPDATED, wxScrollEvent, CmdSliderUpdated )
  WXS_EV_END()
}

wxsSlider::wxsSlider( wxsItemResData* Data ):
  wxsWidget( Data, &Reg.Info, wxsSliderEvents, wxsSliderStyles ),
  Value( 0 ),
  Min( 0 ),
  Max( 100 ),
  TickFrequency( 0 ),
  PageSize( 0 ),
  LineSize( 0 ),
  ThumbLength( 0 ),
  Tick( 0 ),
  SelMin( 0 ),
  SelMax( 0 ) {}

void wxsSlider::OnBuildCreatingCode() {
  switch( GetLanguage() ) {
  case wxsCPP: {
    AddHeader( _T( "<wx/slider.h>" ), GetInfo().ClassName, hfInPCH );
    Codef( _T( "%C(%W, %I, %d, %d, %d, %P, %S, %T, %V, %N);\n" ), Value, Min, Max );
    if( TickFrequency ) {
      Codef( _T( "%ASetTickFreq(%d);\n" ), TickFrequency );
    }
    if( PageSize ) {
      Codef( _T( "%ASetPageSize(%d);\n" ), PageSize );
    }
    if( LineSize ) {
      Codef( _T( "%ASetLineSize(%d);\n" ), LineSize );
    }
    if( ThumbLength ) {
      Codef( _T( "%ASetThumbLength(%d);\n" ), ThumbLength );
    }
    if( Tick ) {
      Codef( _T( "%ASetTick(%d);\n" ), Tick );
    }
    if( SelMin || SelMax ) {
      Codef( _T( "%ASetSelection(%d, %d);\n" ), SelMin, SelMax );
    }
    BuildSetupWindowCode();
    return;
  }
  case wxsUnknownLanguage:
  default: {
    wxsCodeMarks::Unknown( _T( "wxsSlider::OnBuildCreatingCode" ), GetLanguage() );
  }
  }
}

wxObject* wxsSlider::OnBuildPreview( wxWindow* Parent, long Flags ) {
  wxSlider* Preview = new wxSlider( Parent, GetId(), Value, Min, Max, Pos( Parent ), Size( Parent ), Style() );
  if( TickFrequency ) {
    Preview->SetTickFreq( TickFrequency, 0 );
  }
  if( PageSize ) {
    Preview->SetPageSize( PageSize );
  }
  if( LineSize ) {
    Preview->SetLineSize( LineSize );
  }
  if( ThumbLength ) {
    Preview->SetThumbLength( ThumbLength );
  }
  if( Tick ) {
    Preview->SetTick( Tick );
  }
  if( SelMin || SelMax ) {
    Preview->SetSelection( SelMin, SelMax );
  }
  return SetupWindow( Preview, Flags );
}

void wxsSlider::OnEnumWidgetProperties( M_Code_unused long Flags ) {
  WXS_LONG( wxsSlider, Value, _T( "Value" ), _T( "value" ), 0 )
  WXS_LONG( wxsSlider, Min, _T( "Min" ), _T( "min" ), 0 )
  WXS_LONG( wxsSlider, Max, _T( "Max" ), _T( "max" ), 100 )
  WXS_LONG( wxsSlider, TickFrequency, _T( "Tick Frequency" ), _T( "tickfreq" ), 0 )
  WXS_LONG( wxsSlider, PageSize, _T( "Page Size" ), _T( "pagesize" ), 0 )
  WXS_LONG( wxsSlider, LineSize, _T( "Line Size" ), _T( "linesize" ), 0 )
  WXS_LONG( wxsSlider, ThumbLength, _T( "Thumb Length" ), _T( "thumb" ), 0 )
  WXS_LONG( wxsSlider, Tick, _T( "Tick" ), _T( "tick" ), 0 )
  WXS_LONG( wxsSlider, SelMin, _T( "Selection Min" ), _T( "selmin" ), 0 )
  WXS_LONG( wxsSlider, SelMax, _T( "Selection Max" ), _T( "selmax" ), 0 )
}
